package com.yc.shadowdemo.repository

import com.yc.commontlib.base.YcBaseViewModel
import com.yc.commontlib.base.YcRepository
import com.yc.commontlib.extension.checkNet
import com.yc.commontlib.net.YcResult
import com.yc.shadowdemo.data.json.VersionJson
import com.yc.shadowdemo.net.ApiService
import com.yc.shadowdemo.viewmodel.WelcomeVM
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlin.reflect.KProperty

/**
 * Creator: yc
 * Date: 2021/6/15 18:10
 * UseDes:
 */
class VersionRepository(private val apiService: ApiService) : YcRepository() {
    /**
     * 版本更新
     */
    fun getVersion(): Flow<YcResult<VersionJson>> {
        return flow {
            val json = apiService
                .getVersion()
            emit(YcResult.Success((json.data!!)))
        }.checkNet()
    }

    fun getVersion2(): Flow<YcResult<VersionJson>> = ycFlow {
        val json = apiService.getVersion()
        YcResult.Success((json.data!!))
    }


}